package com.gxa.controller.employee;

import com.gxa.common.R.ResponseData;
import com.gxa.pojo.Employee;
import com.gxa.service.employee.*;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 员工Controller层
 */
@Controller
@Api(value = "员工管理test",tags = "员工管理接口API")
@RequestMapping("/employee")
@RequiresPermissions({"员工管理"})
public class EmployeeController {

    @Autowired(required = false)
    private EmployeeService employeeService;
    @Autowired(required = false)
    private WorkEmployeeService workEmployeeService;
    @Autowired(required = false)
    private QuitEmployeeService quitEmployeeService;
    @Autowired(required = false)
    private BlackEmployeeService blackEmployeeService;
    @Autowired(required = false)
    private AddEmployeeService addEmployeeService;

    //分页查询除黑名单员工外的所有员工信息
    @RequestMapping(value = "/selectAllEmployeeList",method = RequestMethod.GET)
    @ApiOperation(value = "分页+模糊查询所有员工信息",notes = "提交页数和每页显示条数，姓名关键字查询",httpMethod = "get", response = ResponseData.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage", value = "当前页数", required = true, dataType = "String"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数", required = true, dataType = "String"),
            @ApiImplicitParam(name = "findKeyword", value = "姓名模糊关键字", required = false, dataType = "String")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public ResponseData selectAllEmployeeList(@RequestParam(name = "currentPage") String currentPage,
                                              @RequestParam(name = "pageSize") String pageSize,
                                              @RequestParam(name = "findKeyword" ,required = false) String findKeyword) {
        return employeeService.selectAllEmployeeList(currentPage,pageSize,findKeyword);
    }

    //将员工在职状态设为离职状态
    @RequestMapping(value = "/setDepartEmployee",method = RequestMethod.POST)
    @ApiOperation(value = "设置离职员工",notes = "将员工在职状态设为离职状态",httpMethod = "post", response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public ResponseData setDepartEmployee(@RequestBody @ApiParam(name = "Employee",value = "员工信息") Employee employee) {
        return employeeService.setDepartEmployee(employee);
    }

    //编辑员工基本信息
    @RequestMapping(value = "/updateEmployee",method = RequestMethod.POST)
    @ApiOperation(value = "编辑员工基本信息",notes = "编辑员工的信息",httpMethod = "post", response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public ResponseData updateEmployee(@RequestBody Employee employee) {
        return employeeService.updateEmployee(employee);
    }

    //删除员工基本信息
    @RequestMapping(value = "/delEmployee",method = RequestMethod.POST)
    @ApiOperation(value = "删除员工基本信息",notes = "删除员工基本信息",httpMethod = "post", response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public ResponseData delEmployee(@RequestParam(name = "idList[]") List<Integer> idList) {
        idList.add(20);
        idList.add(21);
        idList.add(22);
        return employeeService.delEmployee(idList);
    }

    //查询所有在职员工信息
    @RequestMapping(value = "/selectAllWorkEmployeeList",method = RequestMethod.GET)
    @ApiOperation(value = "分页+模糊查询所有在职员工信息",notes = "提交页数和每页显示条数，姓名关键字查询",httpMethod = "get", response = ResponseData.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage", value = "当前页数", required = true, dataType = "String"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数", required = true, dataType = "String"),
            @ApiImplicitParam(name = "findKeyword", value = "姓名模糊关键字", required = false, dataType = "String")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public ResponseData selectAllWorkEmployeeList(@RequestParam(name = "currentPage") String currentPage,
                                                  @RequestParam(name = "pageSize") String pageSize,
                                                  @RequestParam(name = "findKeyword" ,required = false) String findKeyword){
        return workEmployeeService.selectAllWorkEmployeeList(currentPage,pageSize,findKeyword);
    }

    //查询所有离职员工信息
    @RequestMapping(value = "/selectAllQuitEmployeeList",method = RequestMethod.GET)
    @ApiOperation(value = "分页+模糊查询所有离职员工信息",notes = "提交页数和每页显示条数，姓名关键字查询",httpMethod = "get", response = ResponseData.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage", value = "当前页数", required = true, dataType = "String"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数", required = true, dataType = "String"),
            @ApiImplicitParam(name = "findKeyword", value = "姓名模糊关键字", required = false, dataType = "String")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public ResponseData selectAllQuitEmployeeList(@RequestParam(name = "currentPage") String currentPage,
                                                  @RequestParam(name = "pageSize") String pageSize,
                                                  @RequestParam(name = "findKeyword" ,required = false) String findKeyword) {
        return quitEmployeeService.selectAllQuitEmployeeList(currentPage,pageSize,findKeyword);
    }

    //将离职员工进行拉黑处理
    @RequestMapping(value = "/setBlackEmployee",method = RequestMethod.POST)
    @ApiOperation(value = "拉黑离职员工",notes = "将离职员工进行拉黑处理",httpMethod = "post", response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public ResponseData setBlackEmployee(@RequestBody Employee employee) {
        return quitEmployeeService.setBlackEmployee(employee);
    }

    //查询所有黑名单员工信息
    @RequestMapping(value = "/selectAllBlackEmployeeList",method = RequestMethod.GET)
    @ApiOperation(value = "分页+模糊查询所有离职黑名单员工信息",notes = "提交页数和每页显示条数，姓名关键字查询",httpMethod = "get", response = ResponseData.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage", value = "当前页数", required = true, dataType = "String"),
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数", required = true, dataType = "String"),
            @ApiImplicitParam(name = "findKeyword", value = "姓名模糊关键字", required = false, dataType = "String")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public ResponseData selectAllBlackEmployeeList(@RequestParam(name = "currentPage") String currentPage,
                                                   @RequestParam(name = "pageSize") String pageSize,
                                                   @RequestParam(name = "findKeyword" ,required = false) String findKeyword){
       return blackEmployeeService.selectAllBlackEmployeeList(currentPage,pageSize,findKeyword);
    }

    //将黑名单员工状态修改为离职员工或在职员工状态
    @RequestMapping(value = "/updateBlackStatus",method = RequestMethod.POST)
    @ApiOperation(value = "更改黑名单员工状态",notes = "将黑名单员工状态修改为离职状态或者在职",httpMethod = "post", response = ResponseData.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "员工编号id", required = true, dataType = "String"),
            @ApiImplicitParam(name = "states", value = "状态（1:在职  2:白名单(离职)  3:黑名单）", required = true, dataType = "String")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public ResponseData updateBlackStatus(@RequestParam(name = "id") String id,@RequestParam(name = "states") String states) {
        return blackEmployeeService.updateBlackStatus(id,states);
    }

    //从数据库中返回下一个新增员工的编号
    @RequestMapping(value = "/nextEmployeeId",method = RequestMethod.GET)
    @ApiOperation(value = "新录入员工的编号",notes = "从数据库中返回下一个新增员工的编号",httpMethod = "get", response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public ResponseData nextEmployeeId() {
        return addEmployeeService.nextEmployeeId();
    }

    //添加员工基本信息
    @RequestMapping(value = "/addEmployee",method = RequestMethod.POST)
    @ApiOperation(value = "添加员工基本信息",notes = "录入员工的基本信息",httpMethod = "POST", response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public ResponseData addEmployee(@RequestBody Employee employee) {
        return addEmployeeService.addEmployee(employee);
    }
}
